using System;

namespace ElfBinary
{
	public class ElfHeader32
	{

		public ElfType Type { get { return  (ElfType)e_type; }}
		public ElfMachine Machine { get { return (ElfMachine)e_machine; }}
		public ElfVersion Version { get { return (ElfVersion)e_version; }}

		public uint EntryPointAddress { get { return    e_entry; }}
		public uint ProgramHeaderFileOffset{ get{ return     e_phoff; }}
		public uint   SectionHeaderFileOffset {get { return    e_shoff; }}
		public uint   ProcessorFlags { get { return   e_flags; }}
		public ushort  ElfHeaderSize { get { return     e_ehsize; }}
		public ushort   ProgramHeaderRecordSize { get { return    e_phentsize; }}
		public ushort   ProgramHeaderEntryCount { get { return   e_phnum; }}
		public ushort    SectionHeaderEntrySize { get { return   e_shentsize; }}
		public ushort    SectionHeaderEntryCount { get { return  e_shnum; }}
		public ushort    SectionHeaderStringEntryIndex { get { return   e_shstrndx; }}

		public ElfIdentification Identity { get; set;}

		public ElfHeader32 ()
		{
		}

		public void Read(System.IO.Stream s)
		{
			byte[] b = new byte[4];

			s.Read (b, 0, 2);
			e_type = 	BitConverter.ToUInt16 (b, 0);
		
			s.Read (b, 0, 2);
			e_machine = BitConverter.ToUInt16 (b, 0);

			s.Read (b, 0, 4);
			e_version = BitConverter.ToUInt32 (b, 0);

			s.Read (b, 0, 4);
			e_entry = BitConverter.ToUInt32 (b, 0);

			s.Read (b, 0, 4);
			e_phoff = BitConverter.ToUInt32 (b, 0);

			s.Read (b, 0, 4);
			e_shoff = BitConverter.ToUInt32 (b, 0);

			s.Read (b, 0, 4);
			e_flags = BitConverter.ToUInt32 (b, 0);

			s.Read (b, 0, 2);
			e_ehsize = BitConverter.ToUInt16 (b, 0);

			s.Read (b, 0, 2);
			e_phentsize = BitConverter.ToUInt16 (b, 0);

			s.Read (b, 0, 2);
			e_phnum = BitConverter.ToUInt16 (b, 0);

			s.Read (b, 0, 2);
			e_shentsize = BitConverter.ToUInt16 (b, 0);

			s.Read (b, 0, 2);
			e_shnum = BitConverter.ToUInt16 (b, 0);

			s.Read (b, 0, 2);
			e_shstrndx = BitConverter.ToUInt16 (b, 0);
		}

		ushort      e_type;
		ushort      e_machine;
		uint   	   e_version;
		uint      e_entry;
		uint       e_phoff;
		uint       e_shoff;
		uint      e_flags;
		ushort      e_ehsize;
		ushort      e_phentsize;
		ushort      e_phnum;
		ushort      e_shentsize;
		ushort      e_shnum;
		ushort      e_shstrndx;
	}

//		Figure 4-2: 32-Bit Data Types
//
//	Name 	Size 	Alignment 	Purpose
//	Elf32_Addr 	4 	4 	Unsigned program address
//	Elf32_Off 	4 	4 	Unsigned file offset
//	Elf32_Half 	2 	2 	Unsigned medium integer
//	Elf32_Word 	4 	4 	Unsigned integer
//	Elf32_Sword 	4 	4 	Signed integer
//	unsigned char 	1 	1 	Unsigned small integer


}

